package com.zm.demo.core.leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zoum
 * @create 2020/1/17 10:54
 */
public class FindOcurrences {

    public String[] findOcurrences(String text, String first, String second) {
        if(text == null || text.length() == 0){
            return null;
        }
        String[] s = text.split(" ");

        List<String> list = new ArrayList<>();
        for(int i = 0; i<s.length-2; i++){
            if(s[i].equals(first)&& s[i+1].equals(second)){
                list.add(s[i+2]);
            }
        }

        String[]result = list.toArray(new String[0]);
        return result;
    }
}
